package com.example.taximeter.bean;


import com.alibaba.fastjson.annotation.JSONField;
import com.example.taximeter.config.GlobalParam;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.sql.Blob;
import java.util.Date;
import java.util.UUID;

/**
 * 文件管理
 */
public class FileInfo {

    @NotEmpty(message = "文件id不能为空", groups = GroupUpdate.class)
    @Length(min = 32,max = 32, message = "文件id格式错误", groups = GroupUpdate.class)
    private String fileid;//文件id--主键

    @Length(min = 32,max = 32, message = "关联id格式错误", groups = GroupUpdate.class)
    private String ownerid;//上传关联id

    @Length(min = 0,max = 50, message = "文件名格式错误", groups = GroupUpdate.class)
    private String filename;//文件名

    @Length(min = 0,max = 200, message = "文件地址格式错误", groups = GroupUpdate.class)
    private String fileurl;//文件地址

    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private Date uploadtime;//上传时间

    private Blob filecon;//升级文件内容


    @Override
    public String toString() {
        return "FileInfo{" +
                "fileid='" + fileid + '\'' +
                ", ownerid='" + ownerid + '\'' +
                ", filename='" + filename + '\'' +
                ", fileurl='" + fileurl + '\'' +
                ", uploadtime=" + uploadtime +
                ", filecon=" + filecon +
                '}';
    }

    public FileInfo() {
    }

    public FileInfo(String fileid, String ownerid, String filename, String fileurl){
        this.ownerid = ownerid;
        this.filename = filename;
        this.fileurl = fileurl;
        this.uploadtime = GlobalParam.getTime();
        if(fileid==null){
            this.fileid =  UUID.randomUUID().toString().replaceAll("-","");
        }else {
            this.fileid = fileid;
        }
    }
    public String getFileid() {
        return fileid;
    }

    public void setFileid(String fileid) {
        this.fileid = fileid;
    }

    public String getOwnerid() {
        return ownerid;
    }

    public void setOwnerid(String ownerid) {
        this.ownerid = ownerid;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getFileurl() {
        return fileurl;
    }

    public void setFileurl(String fileurl) {
        this.fileurl = fileurl;
    }

    public Date getUploadtime() {
        return uploadtime;
    }

    public void setUploadtime(Date uploadtime) {
        this.uploadtime = uploadtime;
    }

    public Blob getFilecon() {
        return filecon;
    }

    public void setFilecon(Blob filecon) {
        this.filecon = filecon;
    }
}
